<?php
// 本类由系统自动生成，仅供测试用途
class BbsAction extends Action {
	
    public function index(){
    	$this->getMenu();
    	
    	$bbs = M('comments');
    	
    	$cid = $this->_get('cid','htmlspecialchars,strip_tags',0);
    	
    	//分页功能
		import("ORG.Util.Page");// 导入分页类
		$count      = $bbs->where('cid = '.$cid)->count();// 查询满足要求的总记录数
		$Page       = new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
		$Page->setConfig('theme','共有%totalRow%%header% 第%nowPage%页/共%totalPage%页 %first%%upPage%%linkPage%%downPage%%end%');
		//获取数据
		$data = $bbs->where('cid = '.$cid)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		
		$Page->setConfig('first','<<第一页');
		$Page->setConfig('last','最后一页>>');
		$show       = $Page->show();// 分页显示输出
		$this->assign('page',$show);// 赋值分页输出
		$this->assign('data',$data);
    	
    	$data = $bbs->select();
    	
    	$this->display();
    }
    
    public function changestatus(){
	    $this->getMenu();
	    
	    $id = $this->_get('id');
	    $status = $this->_get('status');
	    
	    $bbs = M('comments');
	    
	    $data = array('status'=>$status);

	    if($bbs->where('id = '.$id)->save($data)){
		  	$this->success('更改成功');
	    }else{
		    $this->error('更改失败');
	    }
    }
    
    public function delete(){
    	$this->getMenu();
    	
    	$id = $this->_get('id');
    	
    	$bbs = M('comments');
    	
    	
	    if($bbs->where('id='.$id)->delete()){
			$this->success('删除成功');
		}else{
			$this->error('删除失败');
		}
    }
    
    public function getMenu(){
    	//检测是否为登陆状态
	    R("Login/isLogin");
    	
    	//获取MENU
    	$menu = include(COMMON_PATH.'menu.php');
		$this->assign('menu', $menu);
    }
}